<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content">
            <div class="Post">
                <h:form id="filter">
                    <h:panelGrid columns="4" cellpadding="3" style="width: 400px;height: 50px">
                        <p:selectCheckboxMenu value="#{assignModifyBean.selectedSubject}" label="Subject" >  
                            <f:selectItems value="#{assignModifyBean.kantorsSubjects}" var="subjectNow" itemValue="#{subjectNow.code}"
                                           itemLabel="#{subjectNow.code}"/>  
                        </p:selectCheckboxMenu> 
                        <p:commandButton value="Apply filter" action="#{assignModifyBean.applyFilter()}" ajax="true" update=":assignmentsForm"/>   
                    </h:panelGrid> 
                </h:form>
            </div>
            <div class="Post">
                <h:form id="assignmentsForm">  
                    <p:dataTable  var="assignment" value="#{assignModifyBean.kantorsAssignments}"  
                                  selection="#{assignModifyBean.selectedAssignment}" 
                                  emptyMessage="No assignments  were find by specific criteria"
                                  paginator="true" rows="10" selectionMode="single"
                                  rowKey="#{assignment.id}" paginatorAlwaysVisible="false"
                                  >  
    
                        <f:facet name="header">  
                            Select assignments to edit
                        </f:facet>  

                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Label" />  
                            </f:facet>  
                            <h:outputText value="#{assignment.template.name}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Description" />  
                            </f:facet>  
                            <h:outputText value="#{assignment.template.description}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Date of assignment" />  
                            </f:facet>  
                            <h:outputText value="#{assignment.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Deadline" />  
                            </f:facet>  
                            <h:outputText value="#{assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                          <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Start time" />  
                            </f:facet>  
                              <h:outputText value="#{assignment.dateOfStart}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Type" />  
                            </f:facet>  
                            <h:outputText value="#{assignment.type}" >
                            </h:outputText>
                        </p:column> 
                        <p:column>  
                            <f:facet name="header">  
                                <h:outputText value="Max score" />  
                            </f:facet>  
                            <h:outputText value="#{assignment.maxScore}" >
                            </h:outputText>
                        </p:column> 
                        <f:facet name="footer">
                            <p:commandButton value="Details"
                                             update=":taskDetail:display,:taskDetail:assingmentSubmit" action="#{assignModifyBean.loadAssignmentsSubmit()}" icon="ui-icon-search" ajax="true" oncomplete="taskDialog.show()"/> 
                                <p:commandButton value="Remove"
                                                 update=":assignmentsForm" icon="ui-icon-trash" action="#{assignModifyBean.removeSelectedAssignment()}" ajax="true"/>  
                        </f:facet>
                    </p:dataTable>  
                    <h:outputText value="To select or unselect use CTR"/>
                </h:form>
            </div>
             <!--Start OF Dialog with main description -->
            <p:dialog header="Task detail: #{assignModifyBean.selectedAssignment.template.name}" widgetVar="taskDialog" resizable="false" 
                      width="1000" height="600"  modal="true" appendToBody="true"
                      dynamic="true"  >  
                <h:form id="taskDetail">
                    <h:panelGrid id="display" columns="2" cellpadding="4" title="Assigned Task">  
                        <h:outputText value="Label"/>
                        <h:outputText value="#{assignModifyBean.selectedAssignment.template.name}" />
                        <h:outputText value="Description"/>
                        <h:outputText value="#{assignModifyBean.selectedAssignment.template.description}" />
                        <h:outputText value="Subject"/>
                        <h:outputText value="#{assignModifyBean.selectedAssignment.subject.code}" />
                        <h:outputText value="Type"/>
                        <h:outputText value="#{assignModifyBean.selectedAssignment.type}" />
                        <h:outputText value="Students" />
                        <p:commandButton value="Students"  ajax="true" action="#{assignModifyBean.loadAssignmentPersons()}" oncomplete="userDialog.show();" update=":usersTable"/>   
                        <h:outputText value="Date of assignment:"/>
                        <h:outputText value="#{assignModifyBean.selectedAssignment.dateOfAssignment}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                        <h:outputText value="Max score"/>
                        <h:inputText value="#{assignModifyBean.selectedAssignment.maxScore}" />
                        <h:outputText value="Deadline"/>                 
                        <p:calendar required="true" value="#{assignModifyBean.selectedAssignment.deadline}" pattern="dd.MM.yyyy HH:mm"  timeZone="Europe/Prague" /> 
                          <h:outputText value="Date of start"/>                 
                          <p:calendar required="true" value="#{assignModifyBean.selectedAssignment.dateOfStart}" pattern="dd.MM.yyyy HH:mm"  timeZone="Europe/Prague" />            

                        <h:outputText value="Template files" />
                        <p:commandButton value="Template file"  ajax="true"  onclick="fileDialog.show();" update=":templateFiles"/>                
                    </h:panelGrid>  
                    <p:dataTable  var="task" value="#{assignModifyBean.assignmentSubmits}"  
                                  paginatorAlwaysVisible="false"
                                  styleClass="facesFont" 
                                  emptyMessage="No task was founded"
                                  paginator="true" rows="10" selectionMode="single"
                                  rowKey="#{task.id}" id="assingmentSubmit" selection="#{assignModifyBean.selectedAssignmentSubmit}"> 
                        <p:ajax event="rowSelect"  
                                update=":dialogFiles" listener="#{assignModifyBean.loadVersions()}"  oncomplete="dlg1.show()"/>      
                        <f:facet name="header">  
                            <h:outputText value="Submitted task by students" style="font-size: 12px"/>
                        </f:facet>  
                        <p:column headerText="Label">                   
                            <h:outputText value="#{task.assignment.template.name}" />  
                        </p:column>  
                        <p:column headerText="Date of submit">  
                            <h:outputText value="#{task.dateOfSubmit}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Deadline">  
                            <h:outputText value="#{task.assignment.deadline}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Assigned">                    
                            <h:outputText value="#{task.assignment.dateOfAssignment}" >
                                <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="State">  
                            <h:outputText value="#{task.stateOfTask}" >                     
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Type">                  
                            <h:outputText value="#{task.assignment.type}" />
                        </p:column>  
                        <p:column headerText="Student">   
                            <h:outputText value="#{task.student.surname} #{task.student.name}" >                   
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Login">   
                            <h:outputText value="#{task.student.login}" >   
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Subject">  
                            <h:outputText value="#{task.assignment.subject.code}" >                     
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Grade">  
                            <h:outputText value="#{task.grade}" >                     
                            </h:outputText>
                        </p:column>  
                    </p:dataTable>  
                    <p:commandButton value="Close" 
                                     ajax="true" oncomplete="taskDialog.hide();"></p:commandButton>
                    <p:commandButton value="Modify" action="#{assignModifyBean.updateAssignment()}"
                                     ajax="true" oncomplete="taskDialog.hide();" update=":assignmentsForm"></p:commandButton>
                </h:form>
            </p:dialog>  
            <!--END OF Dialog with main description -->
            <p:dialog width="870" height="400" header="Files with task: #{assignModifyBean.selectedAssignment.template.name}"
                      widgetVar="dlg1" modal="true" dynamic="true" appendToBody="true"
                      >
                <h:form id="dialogFiles">
                <p:dataTable var="taskFile" value="#{assignModifyBean.assignmentVersionsFile}" 
                             rowKey="#{taskFile.id}" paginator="true" 
                             paginatorAlwaysVisible="false" rows="10" >  
                    <p:column headerText="File" >  
                        <h:outputText title="file" value="#{taskFile.fileName}"  />  
                    </p:column>
                      <p:column headerText="Size" >  
                          <h:outputText title="size" value="#{taskFile.fileSize}"  />  
                    </p:column>
                    <p:column headerText="Description">  
                        <h:outputText value="#{taskFile.description}" />  
                    </p:column>
                    <p:column headerText="Date of submit">  
                        <h:outputText value="#{taskFile.version.dateOfSubmit}" >
                            <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                        </h:outputText>
                    </p:column>
                    <p:column headerText="Version">  
                        <h:outputText value="#{taskFile.version.numberOfVersion}" />  
                    </p:column>
                      <p:column headerText="Sender">  
                          <h:outputText value="#{taskFile.version.submittedStudent.name} #{taskFile.version.submittedStudent.surname}" />  
                    </p:column>
                    <p:column headerText="Download">  
                        <p:commandButton value="Download" ajax="false">  
                            <p:fileDownload value="#{assignModifyBean.downloadFilesByTask(taskFile)}" />  
                        </p:commandButton> 
                    </p:column> 
                </p:dataTable>
                </h:form>
            </p:dialog>
            <p:dialog width="870" height="400" header="Submitted files with task: #{assignModifyBean.selectedAssignment.template.name}"
                      widgetVar="fileDialog" modal="true" dynamic="true"  appendToBody="true"
                      >
                <h:form id="templateFiles">
                <p:dataTable var="templateFile" value="#{assignModifyBean.selectedAssignment.template.templateFiles}" 
                             rowKey="#{templateFile.id}" paginator="true" 
                             paginatorAlwaysVisible="false" rows="10" >  
                    <p:column headerText="File" >  
                        <h:outputText title="file" value="#{templateFile.fileName}"  />  
                    </p:column>
                    <p:column headerText="File" >  
                        <h:outputText title="file" value="#{templateFile.fileSize}"  />  
                    </p:column>
                    <p:column headerText="Download">  
                        <p:commandButton value="Download" ajax="false">  
                            <p:fileDownload value="#{assignModifyBean.download(templateFile)}" />  
                        </p:commandButton> 
                    </p:column> 
                </p:dataTable>
                </h:form>
            </p:dialog>
            <p:dialog width="900" height="400" header="Users on task" appendToBody="true"
                      widgetVar="userDialog" modal="true" dynamic="true" 
                      >
                <h:form id="usersTable">
                <p:dataTable var="student" value="#{assignModifyBean.assignmentStudent}"
                             emptyMessage="No students were selected" rendered="#{assignModifyBean.isStudentTask}"
                             rowKey="#{student.login}" paginator="true" paginatorAlwaysVisible="false" rows="10">  
                    <f:facet name="header">  
                        Students on assignment
                    </f:facet>  
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Name" />  
                        </f:facet>  
                        <h:outputText value="#{student.name}" />  
                    </p:column>  
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Surname" />  
                        </f:facet>  
                        <h:outputText value="#{student.surname}" />  
                    </p:column> 
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Login" />  
                        </f:facet>  
                        <h:outputText value="#{student.login}" >
                            <f:converter converterId="StringConverter" />
                        </h:outputText>
                    </p:column> 
                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="E-mail" />  
                        </f:facet>  
                        <h:outputText value="#{student.email}" >
                            <f:converter converterId="StringConverter" />
                        </h:outputText>
                    </p:column> 
                </p:dataTable>     
                <p:dataTable var="group" value="#{assignModifyBean.assignmetGroup}"
                             emptyMessage="No students were selected" rendered="#{assignModifyBean.isGroupTask}"
                             rowKey="#{group.id}" paginator="true" paginatorAlwaysVisible="false" rows="10">  
                    <f:facet name="header">  
                        Group on assignment
                    </f:facet>  
                    <p:row>  
                        <p:column headerText="Login" />  
                        <p:column headerText="Name" />  
                        <p:column headerText="Surname" />
                     
                    </p:row>  
                    <p:subTable var="student" value="#{group.MStudents}">  
                        <f:facet name="header">  
                            <h:outputText value="Group: #{group.code}" />
                        </f:facet>
                        <p:column>  
                            <h:outputText value="#{student.login}"/>
                        </p:column>

                        <p:column>  
                            <h:outputText value="#{student.name}"/>
                        </p:column> <p:column>  
                            <h:outputText value="#{student.surname}"/>
                        </p:column>

                    </p:subTable>
                </p:dataTable>  
                <p:dataTable var="team" value="#{assignModifyBean.assignmentTeam}"
                             emptyMessage="No students were selected" rendered="#{assignModifyBean.isTeamTask}"
                             rowKey="#{team.id}" paginator="true" paginatorAlwaysVisible="false" rows="10">  
                    <f:facet name="header">  
                        Teams on assignment
                    </f:facet>  
                    <p:columnGroup type="header">  
                        <p:row>  
                            <p:column headerText="Login" />  
                            <p:column headerText="Name" />  
                            <p:column headerText="Surname" />
                            <p:column headerText="E-mail" />  
                        </p:row>  
                    </p:columnGroup>  
                    <p:subTable var="student" value="#{team.getmStudents()}">  
                        <f:facet name="header">  
                            <h:outputText value="Team: #{team.name}" />
                        </f:facet>
                        <p:column>  
                            <h:outputText value="#{student.login}"/>
                        </p:column>
                        <p:column>  
                            <h:outputText value="#{student.name}"/>
                        </p:column> <p:column>  
                            <h:outputText value="#{student.surname}"/>
                        </p:column>   
                        <p:column>  
                            <h:outputText value="#{student.email}"/>
                        </p:column>    
                    </p:subTable>
                </p:dataTable>  
                    </h:form>
            </p:dialog>
        </ui:define>
    </ui:composition>
</html>